package com.agentlab.imitation.common;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.agentlab.imitation.bean.User;
import com.agentlab.imitation.bean.UserWish;
import com.agentlab.imitation.bean.WishList;

public class CommonMethod {

	public static User getUserFromSession() {
		HttpServletRequest req = ServletActionContext.getRequest();
		HttpSession session = req.getSession();
		User user = (User) session.getAttribute(CommonConstant.USER_SESSION);
		return user;
	}

	public static Integer getUserIdFromSession() {
		return getUserFromSession().getUserid();
	}

	public static String getPcname() // 当前批次名称
	{
		HttpServletRequest req = ServletActionContext.getRequest();
		HttpSession session = req.getSession();
		String position = (String) session.getAttribute("position");
		return getPcnameByposition(position);
	}
	/**
	 * 当前用户的科类名称
	 * @return
	 */
	public static String getKlname() //
	{
		String klmc = "";
		HttpServletRequest req = ServletActionContext.getRequest();
		HttpSession session = req.getSession();
		UserWish  userWish = (UserWish) session.getAttribute(CommonConstant.USER_WISH_SESSION);
		if(userWish.getKl().equals(CommonConstant.KLDM_LI)){
			klmc = "理工类";
		}
		if(userWish.getKl().equals(CommonConstant.KLDM_WEN)){
			klmc = "文史类";
		}
		return klmc;
	}

	/**
	 * // 当前批次代码
	 * 
	 * @return
	 */
	public static String getPcdm() {
		String pc = "";
		HttpServletRequest req = ServletActionContext.getRequest();
		HttpSession session = req.getSession();
		String position = (String) session.getAttribute("position");
		if (position != null && !"".equals(position)) {
			pc = String.valueOf(position.charAt(0));
			pc = String.valueOf(Integer.parseInt(pc));
		}
		return pc;
	}

	/**
	 * 根据位置返回批次名
	 * 
	 * @param position
	 * @return
	 */
	public static String getPcnameByposition(String position) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("2", "本科第一批");
		map.put("3", "本科第二批");
		map.put("4", "本科第三批");
		String pcname = "";
		if (position != null && !"".equals(position)) {
			String pc = String.valueOf(position.charAt(0));
			pcname = map.get(pc);
		}
		return pcname;
	}
	/**
	 * 院校志愿序号
	 * @return
	 */
	public static String getYxzyxh() {
		String yxzyxh = "";
		HttpServletRequest req = ServletActionContext.getRequest();
		HttpSession session = req.getSession();
		String position = (String) session.getAttribute("position");
		if (position != null && !"".equals(position)) {
			yxzyxh = String.valueOf(position.charAt(1));
		}
		return yxzyxh;
	}
	/**
	 * 院校志愿序号名称
	 * @return
	 */
	public static String getYxzyxhmc(){
		String yxzyxhmc = "";
		int yxzyxh = Integer.parseInt( getYxzyxh() );
		switch(yxzyxh){
			case 1: yxzyxhmc = "第一志愿";break;
			case 2: yxzyxhmc = "第二志愿";break;
			case 3: yxzyxhmc = "第三志愿";break;
		}
		return yxzyxhmc;
	}
}
